package lib.wzh.com.libcore.framework.response;


import com.baomidou.mybatisplus.core.metadata.IPage;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;

/**
 * @Author lib
 * @Date 2021/11/23 18:17
 * @ClassName ResponsePageVo
 * @Version v1.0
 */

public class ResponsePageVo<T> implements Serializable {

    private static final long serialVersionUID = 1L;
    /**
     * 总页数
     */
    private Long total;
    /**
     * 当前页数
     */
    private Long page;

    /**
     * 数据大小
     */
    private Long size;

    /**
     * 错误信息
     */
    private String error;

    /**
     * 数据列表
     */
    private List<T> records;

    public ResponsePageVo(){}

    public ResponsePageVo(String error){
        this.error = error;
    }

    public ResponsePageVo(IPage<T> page){
        this.total = page.getTotal();
        this.page = page.getCurrent();
        this.size = page.getSize();
        this.records = page.getRecords();
    }


    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public Long getPage() {
        return page;
    }

    public Long getSize() {
        return size;
    }

    public void setSize(Long size) {
        this.size = size;
    }

    public void setPage(Long page) {
        this.page = page;
    }

    public String getError() {
        return error;
    }

    public void setError(String error) {
        this.error = error;
    }

    public List<T> getRecords() {
        return records;
    }

    public void setRecords(List<T> records) {
        this.records = records;
    }

    @Override
    public String toString() {
        return "{\"ResponsePageVo\":{"
                + "\"total\":"
                + total
                + ",\"page\":"
                + page
                + ",\"size\":"
                + size
                + ",\"error\":\""
                + error + '\"'
                + ",\"records\":"
                + records
                + "}}";

    }
}
